import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import iView from 'iview';
import 'iview/dist/styles/iview.css';
Vue.use(iView);
Vue.config.productionTip = false;
router.beforeEach(async(to,from,next)=>{
     let isLogin = await  store.dispatch('validate');
     let  needLogin = to.matched.some(match=>{
        match.meta.needLogin
     });
     //需要登陆&&登陆了
     if(needLogin) {
        if(isLogin) {
           next();
        }else {
           next('/login')
        }
     }else {
          //如果登陆 并且路径是login
          if(isLogin && to.path == '/login') {
             next('/')
          }else {
            next();
          }
     }
     next()
})
new Vue({
  router,
  store,
  render: function (h) { return h(App) }
}).$mount('#app')
